use rand::Rng;
use std::cmp::Ordering;
use std::io;

pub fn guess_game() {
    println!("Guess the number!");
    let secret_number = rand::rng().random_range(1..101);
    let mut tries = 0;
    loop {
        println!("Please input your guess: ");
        let mut guess = String::new();
        io::stdin()
            .read_line(&mut guess)
            .expect("Failed to read line");
        tries += 1;
        println!("You guessed: {}", guess);
        let guess = guess
            .trim()
            .parse::<u32>()
            .expect("Please type an integer!");
        match guess.cmp(&secret_number) {
            Ordering::Equal => {
                println!("You guessed: {}, guess times: {}", guess, tries);
                break;
            }
            Ordering::Less => println!("Too small!"),
            Ordering::Greater => println!("Too big!"),
        }
    }
}
